<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('分配HBase表')" />
	<th:block th:include="include :: ztree-css" />
</head>
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-role-edit" th:object="${user}">
			<input id="userId" name="userId" type="hidden" th:field="*{userId}"/>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">用户名称：</label>
				<div class="col-sm-8">
					<input class="form-control" disabled type="text" name="userName" id="userName" th:field="*{userName}">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">HBase表分配：</label>
				<div class="col-sm-8">
					<div id="tableTrees" class="ztree"></div>
				</div>
			</div>
		</form>
	</div>
	<th:block th:include="include :: footer" />
	<th:block th:include="include :: ztree-js" />
	<script type="text/javascript">
	     $(function() {
			var url = ctx + "system/user/userTableTreeData?userId=" + $("#userId").val();
			var options = {
				id: "tableTrees",
		        url: url,
		        check: { enable: true },
		        expandLevel: 0
		    };
			$.tree.init(options);
		});

		function authTableSave() {
			var tables = $.tree.getCheckedNodes();
			console.log(tables)
			var userId = $("#userId").val();

			$.ajax({
				cache : true,
				type : "POST",
				url : ctx + "system/user/authTable",
				data : {
					"userId": userId,
					"tables": tables,
				},
				async : false,
				error : function(request) {
					$.modal.alertError("系统错误");
				},
				success : function(data) {
					$.operate.successCallback(data);
				}
			});
		}
		
		function submitHandler() {
	        if ($.validate.form()) {
				authTableSave();
	        }
	    }
	</script>
</body>
</html>
